package com.zhentao.controller;

import com.zhentao.interfaceclass.ChargeUserInterface;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.model.pojo.user.ChargeUser;
import com.zhentao.model.pojo.user.dto.UserDto;
import com.zhentao.model.pojo.user.param.MessageParam;
import com.zhentao.model.pojo.user.param.UserParam;
import com.zhentao.model.pojo.user.yichang.ChargeUserExpeciton;
import com.zhentao.service.ChargeUserExpecitonService;
import com.zhentao.service.ChargeUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @ClassName: ChargeUserController
 * @Author: 振涛教育_Q
 * @Date: 2024/12/17 9:49
 */
@RestController
@RequestMapping("/auth/user")
public class ChargeUserController {
    @Autowired
    private ChargeUserService chargeUserService;
    @Autowired
    private ChargeUserExpecitonService chargeUserExpecitonService;

    /**
     * @description   charge----user -- 登录接口
     * @author 振涛教育_小Q
     * @date    2024/12/17 9:56
      * @param userDto
     * @return com.zhentao.model.common.dtos.ResponseResult
     */
    @PostMapping("/login")
    @ChargeUserInterface(value = "ChargeUser用户登录")
    public ResponseResult login(@RequestBody UserDto userDto){
        return chargeUserService.login(userDto);
    }


    /**
     * @description   charge----userInfo -- 获取当前登录用户
     * @author 振涛教育_小Q
     * @date    2024/12/17 9:56
     * @return com.zhentao.model.common.dtos.ResponseResult
     */
    @GetMapping("/id")
    public ResponseResult getUserInfo(){
        return chargeUserService.getUserInfo();
    }


    /**
     * @description   charge----messageCode -- 发送短信
     * @author 振涛教育_小Q
     * @date    2024/12/17 9:56
     * @return com.zhentao.model.common.dtos.ResponseResult
     */
    @PostMapping("/message/send/code")
    public ResponseResult messageCode(@RequestBody MessageParam param){
        return chargeUserService.messageCode(param);
    }

    /**
     * @description   charge----registry -- 用户注册
     * @author 振涛教育_小Q
     * @date    2024/12/17 9:56
     * @return com.zhentao.model.common.dtos.ResponseResult
     */
    @PostMapping("/registry")
    public ResponseResult chargeRegistry(@RequestBody UserParam param){
        return chargeUserService.chargeRegistry(param);
    }

    /**
     * @description   charge----myInviteList-- 获取当前登录用户的邀请人
     * @author W177
     * @date    2024/12/17 10:04
     * @return com.zhentao.model.common.dtos.ResponseResult
     */
    @GetMapping("/invite/record")
    public ResponseResult getInviteRecord(){
        return chargeUserService.getInviteRecord();
    }

    /**
     * @description   charge----getInviteIncome -- 获取当前登录用户收益
     * @author W177
     * @date    2024/12/17 10:04
     * @return com.zhentao.model.common.dtos.ResponseResult
     */
    @GetMapping("/invite/income")
    public ResponseResult getInviteIncome(){
        return chargeUserService.getInviteIncome();
    }


    /**
     * @description   charge----updateUserInfo -- 编辑当前用户的基本信息
     * @author 振涛教育_小Q
     * @date   2024/12/22 10:38
     * @return com.zhentao.model.common.dtos.ResponseResult
     */
    @PostMapping("/updateUserInfo")
    public ResponseResult updateUserInfo(@RequestBody UserParam param){
        return chargeUserService.updateUserInfo(param);
    }

    /**
     * @description  退出登录
     * @author 振涛教育_小Q
     * @date    2024/12/22 13:04
      * @param
     * @return com.zhentao.model.common.dtos.ResponseResult
     */
    @GetMapping("/logout")
    public ResponseResult userLogout(){
        return chargeUserService.userLogout();
    }

    /**
     * @description  获取当前用户的可用积分
     * @author 振涛教育_小Q
     * @date    2024/12/22 20:29
      * @param
     * @return com.zhentao.model.common.dtos.ResponseResult
     */
    @GetMapping("/point/get")
    public ResponseResult getUserPoint(@RequestParam(value = "id",required = false) Long id){
        return chargeUserService.getUserPoint(id);
    }


    /**
     * @description  扣减库存
     * @author 振涛教育_小Q
     * @date    2024/12/26 16:38
      * @param point
     * @return com.zhentao.model.common.dtos.ResponseResult
     */
    @GetMapping("/deduction/count")
    public ResponseResult getDeductionCount(@RequestParam(value = "point",required = false) Integer point,
                                            @RequestParam(value = "userId",required = false) Long userId){
        return chargeUserService.getDeductionCount(point,userId);
    }

    /**
     * @description   异常上传
     * @author W177
     * @date    2024/12/27 10:04
     */
    @PostMapping("/user/sendException")
    public ResponseResult sendException(@RequestBody ChargeUserExpeciton exception){
        return chargeUserExpecitonService.sentException(exception);
    }

    //图片上传
    @PostMapping("/user/uploadImg")
    public ResponseResult uploadImg(@RequestParam("file") MultipartFile file){
        return chargeUserService.uploadImg(file);
    }

    //管理端获取用户列表
    @PostMapping("/getUserList")
    public List<ChargeUser> getUserList(){
        return chargeUserService.getUserList();
    }

    //管理端添加用户黑名单
    @GetMapping("/addBlackList")
    public ResponseResult addBlackList(@RequestParam(value = "userId",required = false) Integer userId){
        return chargeUserService.addBlackList(userId);
    }

    //管理端获取用户信息
    @GetMapping("/getUserInfo")
    public ChargeUser getUserInfo(@RequestParam(value = "id",required = false)Long id){
        return chargeUserService.getUser(id);
    }

    //管理端获取异常列表
    @GetMapping("/getExceptionList")
    public List<ChargeUserExpeciton> getExceptionList(){
        return chargeUserExpecitonService.getExceptionList();
    }

    //管理端处理异常
    @PostMapping("/updateException")
    public ResponseResult updateException(@RequestBody(required = false) ChargeUserExpeciton exception){
        return chargeUserExpecitonService.updateException(exception);
    }
}
